import React from 'react';
import {Link} from 'dva/router';
import { Table,Button } from 'antd';
import { getAll } from '../services/article';

const columns = [
    {
        title: 'ID',
        dataIndex: 'id',
        key: 'id',
    },
    {
        title: '标题',
        dataIndex: 'title',
        key: 'title',
    },
    {
        title: '分类',
        dataIndex: 'category',
        key: 'category',
    },
    {
        title: '作者',
        dataIndex: 'author',
        key: 'author',
    },
    {
        title: '图片',
        dataIndex: 'img',
        key: 'img',
        render:(value)=>(<img src={value} alt=""/>)
    },
    {
        title: '阅读量',
        dataIndex: 'hits',
        key: 'hits',
    },
    {
        title: '点赞量',
        dataIndex: 'praise',
        key: 'praise',
    },
    {
        title: '创建时间',
        dataIndex: 'createTime',
        key: 'createTime',
    },
    {
        title: '操作',
        dataIndex: 'edit',
        key: 'edit',
        fixed: 'right',
        render:(value,item)=>(
            <Link to={`/article/${item.id}`}>
            <Button type="primary" size="small">编辑</Button>
            </Link>
        )
    },
];

class ArticlePage extends React.Component {
    state={
        list:[]
    }
    render() {
        return (
            <div>
                <h1>文章列表</h1>
                <hr />
                <Table rowKey={(item)=>item.id}  dataSource={this.state.list} columns={columns} />
            </div>
        );
    }
    componentWillMount() {
        getAll(1).then(({data})=>{
            this.setState({
                list:data.data
            });
        });    
    }
}

ArticlePage.propTypes = {}

export default ArticlePage;